/*
package org.example.util;

import lombok.RequiredArgsConstructor;
import org.example.config.PrinterConfig;
import org.example.dto.OrderDTO;
import org.springframework.stereotype.Component;

import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;

@Component
@RequiredArgsConstructor
public class OrderTemplate {

    private final ESCPOSUtil escposUtil;
    private final PrinterConfig printerConfig;

    private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#0.00");
    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    static {
        DECIMAL_FORMAT.setRoundingMode(RoundingMode.HALF_UP);
    }

    public void printOrder(OutputStream outputStream, OrderDTO order, boolean cutPaper) throws Exception {
        escposUtil.initPrinter(outputStream);

        // 打印公司信息
        printHeader(outputStream);

        // 打印订单信息
        printOrderInfo(outputStream, order);

        // 打印商品列表
        printItems(outputStream, order);

        // 打印金额信息
        printAmountInfo(outputStream, order);

        // 打印二维码
        printQRCode(outputStream, order);

        // 打印页脚
        printFooter(outputStream);

        // 切纸
        if (cutPaper) {
            escposUtil.cutPaper(outputStream);
        }
    }

    private void printHeader(OutputStream outputStream) throws Exception {
        escposUtil.setCenterAlignment(outputStream);
        escposUtil.setFontSize(outputStream, 2, 2);
        escposUtil.setBold(outputStream, true);
        escposUtil.printText(outputStream, printerConfig.getCompanyName() + "\n");

        escposUtil.setFontSize(outputStream, 1, 1);
        escposUtil.setBold(outputStream, false);
        escposUtil.printText(outputStream, printerConfig.getCompanyAddress() + "\n");
        escposUtil.printText(outputStream, "电话: " + printerConfig.getCompanyPhone() + "\n");

        escposUtil.printLineFeed(outputStream, 1);

        // 打印分隔线
        escposUtil.setLeftAlignment(outputStream);
        escposUtil.printText(outputStream, "--------------------------------\n");
    }

    private void printOrderInfo(OutputStream outputStream, OrderDTO order) throws Exception {
        escposUtil.setLeftAlignment(outputStream);
        escposUtil.setBold(outputStream, true);
        escposUtil.printText(outputStream, "订单号: " + order.getOrderId() + "\n");

        escposUtil.setBold(outputStream, false);
        escposUtil.printText(outputStream, "时间: " + order.getOrderTime().format(TIME_FORMATTER) + "\n");
        escposUtil.printText(outputStream, "客户: " + order.getCustomerName() + "\n");
        escposUtil.printText(outputStream, "电话: " + order.getCustomerPhone() + "\n");
        escposUtil.printText(outputStream, "地址: " + order.getCustomerAddress() + "\n");

        escposUtil.printLineFeed(outputStream, 1);
        escposUtil.printText(outputStream, "--------------------------------\n");
    }

    private void printItems(OutputStream outputStream, OrderDTO order) throws Exception {
        // 表头
        escposUtil.setBold(outputStream, true);
        escposUtil.printText(outputStream, String.format("%-18s %4s %8s\n", "商品名称", "数量", "金额"));
        escposUtil.setBold(outputStream, false);
        escposUtil.printText(outputStream, "--------------------------------\n");

        // 商品列表
        for (OrderDTO.OrderItemDTO item : order.getItems()) {
            String line = String.format("%-18s %4d %8s\n",
                    item.getProductName(),
                    item.getQuantity(),
                    DECIMAL_FORMAT.format(item.getSubtotal()));
            escposUtil.printText(outputStream, line);
        }

        escposUtil.printText(outputStream, "--------------------------------\n");
    }

    private void printAmountInfo(OutputStream outputStream, OrderDTO order) throws Exception {
        escposUtil.setBold(outputStream, true);
        escposUtil.printText(outputStream, String.format("%-22s %8s\n", "合计:",
                DECIMAL_FORMAT.format(order.getTotalAmount())));

        if (order.getDiscount().compareTo(BigDecimal.ZERO) > 0) {
            escposUtil.printText(outputStream, String.format("%-22s %8s\n", "优惠:",
                    DECIMAL_FORMAT.format(order.getDiscount().negate())));
        }

        escposUtil.printText(outputStream, String.format("%-22s %8s\n", "实付:",
                DECIMAL_FORMAT.format(order.getPaymentAmount())));

        escposUtil.setBold(outputStream, false);
        escposUtil.printLineFeed(outputStream, 1);
    }

    private void printQRCode(OutputStream outputStream, OrderDTO order) throws Exception {
        escposUtil.setCenterAlignment(outputStream);
        escposUtil.printText(outputStream, "订单二维码\n");

        // 生成订单详情URL
        String qrData = "https://example.com/order/" + order.getOrderId();
        escposUtil.printQRCode(outputStream, qrData);

        escposUtil.printLineFeed(outputStream, 2);
    }

    private void printFooter(OutputStream outputStream) throws Exception {
        escposUtil.setCenterAlignment(outputStream);
        escposUtil.printText(outputStream, printerConfig.getFooterMessage() + "\n");
        escposUtil.printLineFeed(outputStream, 3);
    }
}
*/
